<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="stylesheets/public.css">
    <link rel="stylesheet" href="stylesheets/bootstrap.min.css">
    <script src="javascripts/jquery-1.7.1.min.js"></script>
    <script src="javascripts/bootstrap.min.js"></script>
</head>

<script>
    $(function(){
        var user = '<%=user%>';
        $.ajax({
            type: "GET",
            async:false,
            url: "/getPlatformName",
            dataType:'json',
            success: function(msg){
                for(var i=0;i<msg.length;i++){
                    var options ="<option  value ='"+msg[i].id+"'>"+msg[i].projectname+"</option>";
                    $(".platformname").append(options);
                }
            }
        });

        $('.add_online').click(function(){
            $('.createServerForm').eq(0)[0].reset();
            $('.create_s').show();
        });

        if(user != 'sa'){
            $('.purview').remove();
        }

    });

    function saveServer(){
        var platformname = $('.platformname option:selected') .val();//选中的值
        if(platformname!=""){
            $('.createServerForm').submit();
        }else{
            alert('有未填的选项');
        }
    }

    function existId(){
        var platformid = $('.td_select option:selected').val();
        var sid = $("input[name='sid']").val();
        var appid = $("input[name='appid']").val();

        $.ajax({
            type: "POST",
            async:false,
            url: "/hasPlatformId",
            data:{appid:appid,sid:sid,platformid:platformid},
            dataType:'json',
            success: function(msg){
                if(msg.length>0){
                    alert("已存在");
                    return false;
                }else{
                    saveServer();
                }
            }
        });

    }
</script>

<body>

<div class="box round">
    <h1 class="h2">应用平台</h1>
    <div>
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="/toMainPage">返回服务器列表</a></li>
            </ul>
        </div>
        <div>
            <table class="table table-hover">
                <thead>
                <tr class="">
                    <th>编号</th>
                    <th>服务器名称</th>
                    <th>应用名称</th>
                    <th colspan="4" class="text-center">应用明细</th>
                    <td class="purview"><button class="add_online btn btn-info btn-sm" type="button">增加</button></td>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>项目名称</td>
                    <td>访问域名</td>
                    <td>状态</td>
                    <td>备注</td>
                </tr>
                <%
                var data = JSON.parse(msg);
                if(data!=null){
                data.forEach(function(val,index){
                %>
                <tr>
                    <td ><%=(index+1)%></td>
                    <td><%=servername%></td>
                    <td><%=appname%></td>
                    <td ><%=val.projectname%></td>
                    <td ><%=val.domainname%></td>
                    <td><%=val.status%></td>
                    <td><%=val.remark%></td>
                    <td class="purview"><a href="/deletePlatform?platformid=<%=val.id%>&appid=<%=appid%>&sid=<%=sid%>">删除</a></td>
                </tr>
                <%});
                }
                %>
                </tbody>
            </table>

            <form class="createServerForm" action="/addPlatformName" method="post">
                <table class="create_s" style="display: none">
                    <tr class="platform_td">
                        <td><input class="online_input" type="hidden" name="appid" value="<%=appid%>"></td>
                        <td><input type="hidden" name="sid" value="<%=sid%>"></td>
                        <td><select class="platformname td_select" name="platformid"></select></td>
                        <td><a href="javascript:void(0)" class="online_btn btn btn-default btn-sm" role="button" onclick="existId();">保存</a></td>
                    </tr>
                </table>
            </form>

        </div>

    </div>
</div>

</body>
</html>